#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
电表遥测数据 ORM 模型
对应表：dc_meter_telemetry
职责：只做字段映射与类型转换，不承载业务逻辑。
"""

from datetime import datetime
from decimal import Decimal
from typing import Optional, Dict, Any

from pydantic import BaseModel, ConfigDict


class MeterTelemetry(BaseModel):
	"""电表实时遥测数据 ORM 模型（与 SELECT * 字段顺序一致）"""
	id: int
	msg_id: str
	phase: str
	meter_code: str
	ts: datetime
	voltage: Optional[Decimal] = None
	current: Optional[Decimal] = None
	watt: Optional[Decimal] = None
	temperature1: Optional[Decimal] = None
	temperature2: Optional[Decimal] = None
	ext_json: Optional[Dict[str, Any]] = None  # MySQL JSON -> dict
	total_kwh: Optional[Decimal] = None
	quality: str
	created_at: datetime

	model_config = ConfigDict(
		from_attributes=True,  # 支持 SQL 结果 -> 模型
		populate_by_name=True,  # 允许字段别名
	)
